package com.aplink.generic.pojo.googlemaps;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

public class DirectionsRoutes implements JsonDeserializer<DirectionsRoutes> {
	private DirectionsLeg mDirectionsLeg;
	private String mOverviewPolyline;

	@Override
	public DirectionsRoutes deserialize(JsonElement jsonElement, Type type,
	        JsonDeserializationContext context) throws JsonParseException {
		JsonObject jsonObject = jsonElement.getAsJsonObject();
		mOverviewPolyline = jsonObject.get("overview_polyline")
		        .getAsJsonObject().get("points").getAsString();
		mDirectionsLeg = context.deserialize(jsonObject.get("legs")
		        .getAsJsonArray().get(0), DirectionsLeg.class);
		return this;
	}

	public DirectionsLeg getDirectionsLeg() {
		return mDirectionsLeg;
	}

	public String getOverviewPolyline() {
		return mOverviewPolyline;
	}

	public void setDirectionsLeg(DirectionsLeg directionsLeg) {
		mDirectionsLeg = directionsLeg;
	}

	public void setOverviewPolyline(String overviewPolyline) {
		mOverviewPolyline = overviewPolyline;
	}

}
